package com.lanou.fooddemo.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lanou.fooddemo.R;
import com.lanou.fooddemo.theme.FoodTheme;

/**
 * Created by LiuYan on 2015/8/18.
 * 自定义Toast
 */
public class FoodToast {
    private static Toast toast;
    private static LinearLayout toastLayout;
    public static final int LENGTH_SHORT = Toast.LENGTH_SHORT;
    public static final int LENGTH_LONG = Toast.LENGTH_LONG;
    public static Toast makeText(Context context,CharSequence text, int duration) {
        toast = new Toast(context);

        LayoutInflater inflate = (LayoutInflater)
                context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View viewGroup = inflate.inflate(R.layout.toast_view_layout, null);
        toastLayout = (LinearLayout) viewGroup.findViewById(R.id.toastLayout);

        //设置主题
        setToastTheme();

        TextView textView = (TextView) viewGroup.findViewById(R.id.toastTextView);
        textView.setText(text);

        toast.setDuration(duration);
        toast.setView(viewGroup);
        return toast;
    }

    /**
     * 设置主题
     */
    private static void setToastTheme() {
        toastLayout.setBackgroundColor(FoodTheme.getToastLayoutColor());
    }
}
